package com.example.graduationdesignbackend.controller;


import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import com.example.graduationdesignbackend.entity.User;
import com.example.graduationdesignbackend.res.Res;
import com.example.graduationdesignbackend.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yuze
 * @since 2024-04-07
 */
@RestController
@RequestMapping("/user")
@SaCheckLogin
public class UserController {

    @Autowired
    private IUserService userService;
    @GetMapping("/logout")
    public Res logout(){
        StpUtil.logout(StpUtil.getLoginId());
        return Res.yuze();
    }

    @PutMapping("/editpwd")
    public Res editpwd(@RequestBody User user){
        return userService.editPassword(user);
    }
    @PutMapping()
    public Res editInfo(@RequestBody User user){
        return userService.editInfo(user);
    }
    @GetMapping()
    public Res getInfo(String id){return Res.yuze(userService.getInfo(id));}
}
